﻿using System;
using System.Collections.Generic;
using System.Text;
using CommunityServer.WebServices.MediaGalleries;
using System.IO;
using System.Windows.Forms;

namespace nb.development.csmediamanager
{
    public class Updater
    {
        public Updater(List<MediaGalleryPost> posts, Guid siteid)
        {
            this.posts = posts;
            this.siteid = siteid;
        }

        private List<MediaGalleryPost> posts;
        private Guid siteid;
        public event UploadedPost UpdatedPost;
        public event UploadCompleted UpdateCompleded;

        public void Update()
        {
            try
            {
                MediaGalleriesService mgs = Sites.Instance[siteid].Service;
                int x = 1;
                foreach (MediaGalleryPost post in this.posts)
                {
                    mgs.UpdateMediaGalleryPost(post);
                    if (UpdatedPost != null)
                        UpdatedPost(x, this.posts.Count);
                    x++;
                }
                UpdateCompleded();
            }
            catch (Exception e) { MessageBox.Show("Error:\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
    }
}
